let path = require('path');
let HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    mode: 'development',
    entry: {
        index: './src/index.js'
    },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist')
    },
    // 寻找loader的顺序配置
    resolveLoader: {
        modules: [
            path.resolve(__dirname, 'node_modules'),
            path.resolve(__dirname, 'loaders')
        ]
    },
    devServer: {
        port: 3000,
        // 进度条
        // progress: true,
        // 在dist文件夹中运行
        contentBase: 'dist',
        // createGzip
        compress: true
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './public/index.html'
        })
    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'banner-loader',
                        options: {
                            text: 'written by zeihang',
                            filename: path.resolve(__dirname, './banner.txt')
                        }
                    },
                    {
                        loader: 'babel-loader',
                        options: {
                            presets: ['@babel/preset-env']
                        }
                    }
                ]
            },
            {
                test: /\.(jpg|png|gif)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 1024 * 2
                    }
                }
            }
        ]
    }
}